import java.util.Scanner;

public class Test3 {
    // https://www.nowcoder.com/practice/ffd8b867156d474ebe9f96d70014caa4
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        char[] cc = in.nextLine().toCharArray();
        int ret = 0x3f3f33f;
        for (char c = 'a'; c <= 'z'; c++) {
            int sum = 0;
            for (char ch : cc) {
                sum += Math.min(Math.abs(ch-c), 26-Math.abs(ch-c));
            }
            ret = Math.min(ret, sum);
        }
        System.out.println(ret);
    }
}
